﻿using BestEasyCMS.Core.NPoco;
using BestEasyCMS.Framework.Authentication;
using BestEasyCMS.Framework.CacheStorage;
using BestEasyCMS.Framework.Configuration;
using BestEasyCMS.Framework.CookieStorage;
using BestEasyCMS.Framework.Email;
using BestEasyCMS.Framework.Logging;
using BestEasyCMS.Framework.SessionStorage;
using BestEasyCMS.Framework.UnitOfWork;
using BestEasyCMS.Model.IRepository.Security;
using BestEasyCMS.Repository.Base;
using BestEasyCMS.Repository.Security;
using BestEasyCMS.Service.Impl.Security;
using BestEasyCMS.Service.Impl.Security.Users;
using BestEasyCMS.Service.Interfaces.Security;
using StructureMap;
using StructureMap.Configuration.DSL;

namespace BestEasyCMS.Web.MvcUI
{
    public class BootStrapper
    {
        public static void ConfigureDependencies()
        {
            ObjectFactory.Initialize(x => x.AddRegistry<ControllerRegistry>());
        }
        private class ControllerRegistry : Registry
        {
            public ControllerRegistry()
            {
                ForRequestedType<IFormsAuthentication>().TheDefault.Is.OfConcreteType<AspFormsAuthentication>();
                // Application Settings                 
                ForRequestedType<IApplicationSettings>().TheDefault.Is.OfConcreteType<WebConfigApplicationSettings>();
                //Cookie Service
                ForRequestedType<ICookieStorageService>().TheDefault.Is.OfConcreteType<CookieStorageService>();
                // Email Service                 
                ForRequestedType<IEmailService>().TheDefault.Is.OfConcreteType<TextLoggingEmailService>();
                // Logger
                ForRequestedType<ILogger>().TheDefault.Is.OfConcreteType<Log4NetAdapter>();
                //Session Service
                ForRequestedType<ISessionStorageService>().TheDefault.Is.OfConcreteType<SessionStorageService>();
                //Cache Service
                ForRequestedType<ICacheStorage>().TheDefault.Is.OfConcreteType<HttpContextCacheAdapter>();
                ForRequestedType<IUnitOfWork>().TheDefault.Is.OfConcreteType<UnitOfWork>();
                ForRequestedType<IDbBase>().TheDefault.Is.OfConcreteType<DbBase>();

                //Repository
                ForRequestedType<IRoleRepository>().TheDefault.Is.OfConcreteType<RoleRepository>();
                ForRequestedType<IUserRepository>().TheDefault.Is.OfConcreteType<UserRepository>();
                ForRequestedType<IResourceRepository>().TheDefault.Is.OfConcreteType<ResourceRepository>();
                ForRequestedType<IResourceInRoleRepository>().TheDefault.Is.OfConcreteType<ResourceInRoleRepository>();

                //Service
                ForRequestedType<IRoleService>().TheDefault.Is.OfConcreteType<RoleService>();
                ForRequestedType<IUserService>().TheDefault.Is.OfConcreteType<UserService>();
                ForRequestedType<IResourceService>().TheDefault.Is.OfConcreteType<ResourceService>();
            }
        }
    }
}